/* $Header: method.h,v 2.2 01/10/02 10:30:30 przybyls Exp $ */

/***********************************************************************/
/* INCLUDE FILE NAME:  method.h                                        */
/* ==================                                                  */
/*                                                                     */
/* Author:  John DeGood                                                */
/*                                                                     */
/* COMMENT: Include file for method functions.                         */
/*                                                                     */
/***********************************************************************/

#ifndef METHOD_H
#define METHOD_H

/*****************************/
/*   IFDEFS                  */
/*****************************/

/*****************************/
/*   SYMBOLIC CONSTANTS      */
/*****************************/

/*****************************/
/*   MACROS                  */
/*****************************/

#define MAXINDEX(array, element) (U_INT8)(sizeof(array) / sizeof(element) - 1)

/*****************************/
/*   TYPEDEFS                */
/*****************************/

typedef enum
{
        METH_INT0, METH_INT1, METH_INT2, METH_INT3, METH_ON_OFF, METH_HEX, METH_STR, METH_FILL6, METH_QSTR, METH_CSTR
} METHFORMAT;

typedef enum
{
        GC_ONLY, ALS_ONLY, BOTH
} WKFILE_CONTENTS;

typedef struct
{
        INT32 (* const getFunction)(void *which, U_INT8 ramp_number);
        UI_ERR (* const setFunction)(void *which, INT32 setpt, U_INT8 ramp_number);
        const U_INT8 selector;
        const METHFORMAT format;
} METHCMD_ENTRY;

typedef struct
{
        const INT8 maxindex;
        const METHCMD_ENTRY * const array;
        void * const setpoint;
        UI_ERR (* const preFunction)(void *which);
        UI_ERR (* const postFunction)(void *which);
} METHCMD;

/*****************************/
/*   FUNCTION PROTOTYPES     */
/*****************************/

/* method_ui.c */
UI_ERR MethodExists(U_INT8 number);
UI_ERR CheckMethod(U_INT8 number);
UI_ERR LoadMethod(U_INT8 number);
UI_ERR DcLoadMethod(U_INT8 number, U_INT16 port);
UI_ERR StoreMethod(U_INT8 number);
void DeleteMethod(U_INT8 number);
DATETIME GetMethodDateTime(U_INT8 number);
INT16 GetMethodName (BIT8* string, U_INT8 number);
void  LetMethodName (BIT8* string);
void  SetMethodName (BIT8* string);
void  DCSetMethodName (BIT8* string, BIT8 clear_meth_dirty);

/* setdefault.c */
void   SetDefaultSetpoints(void);
UI_ERR SetDefaultMethod (void);

/* wkfileutil.c */
void UpdateMethodModified (U_INT16 port);
void UpdateMethodDirectory (U_INT16 port);
void UpdateInstStatus(void);
void SavePwrFailInstConfig(void);
void InitializeMethod(void);

UI_ERR DoCmdPreFunction(const METHCMD *cmd);
UI_ERR DoCmdPostFunction(const METHCMD *cmd);

UI_ERR SetWkfileParam(BIT8 *param, const METHCMD *cmdGroup, int cmdIndex);
UI_ERR GetWkfileParam(BIT8 *param, const METHCMD *cmdGroup, int cmdIndex);

UI_ERR CheckWorkfile(BIT8 *p, U_INT16 length, BIT8 *crc, WKFILE_CONTENTS contents, U_INT16 chan);
void InstallWorkfile(BIT8 *p, U_INT16 length, BIT8 *crc, WKFILE_CONTENTS contents, U_INT16 chan);

/* methlist.c */
void ExpandString(BIT8 *in, BIT8 *out, U_INT8 width, U_INT8 indent, BIT8 fillChar, BIT8 singleValue);
void RewindMethodFmt(U_INT16 chan);
INT16 ReadMethodFmt(BIT8 *chars,U_INT16 chan);

/* crc16.c */
/* Used for ROM checksum in startup.c, so must be in boot section */
#ifndef mccabe
#pragma SECTION PROG=boot
#endif

U_INT16 crc16(U_INT8 *bytes, INT32 len);

#ifndef mccabe
#pragma SECTION UNDO
#endif

#endif
